from django.shortcuts import render

# Create your views here.
from django.utils.decorators import method_decorator
from django.views import View
from django.http import HttpResponse
from django.template import loader


def my_decorator(func):
    def wrapper(request, *args, **kwargs):
        response = func(request, *args, **kwargs)
        return response

    return wrapper


class GetMixin(object):
    def get(self, request, ):
        '''
            处理get请求
        '''
        print(request.method)
        return HttpResponse('get')


class PostMixin(object):
    def post(self, request):
        '''
            处理post请求
        '''
        print(request.method)
        return HttpResponse('post')


class GetPostMixin(PostMixin, GetMixin):
    pass


# @method_decorator(my_decorator, name='dispatch')
class Index(View, GetPostMixin):
    # @method_decorator(my_decorator)
    # def get(self, request, ):
    #     '''
    #         处理get请求
    #     '''
    #     print(request.method)
    #     return HttpResponse('get')
    #
    # def post(self, request):
    #     '''
    #         处理post请求
    #     '''
    #     print(request.method)
    #     return HttpResponse('post')


    def put(self, request,a):
        # 获取模板
        # template=loader.get_template('index.html')
        #

        # if a=='1.0':
        #
        # elif a=='2.0':

        context = {'title': 'python1111111',

                   'a_list': [1, 2, 3, 4],
                   'name': 'python11'

                   }

        # return HttpResponse(template.render(context))
        #
        return render(request, 'index.html', context)
